<?php
$redis = new redis();
$redis->connect('127.0.0.1', 6379);
//$redis->auth('Np3jftX7808X')

/**
 * 序列化
 * Redis::OPT_SERIALIZER php的序列化serialize()
 * Redis::OPT_PREFIX JSON 序列化 (Redis::SERIALIZER_JSON)
 * 其他的序列化方式 MessagePack IGBinary 都需要php安装扩展
 * serialize() 导致set() 变量 incr无法自增
 * JSON 序列化 没有问题
 */
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
$redis->setOption(Redis::OPT_PREFIX, 'myincr_seri:');
//$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_JSON);
//$redis->setOption(Redis::OPT_PREFIX, 'myincr:');
$keys = ['incr' => 'incr', 'incr1' => 'incr1', 'incrStr' => 'insrStr'];
$redis->incr($keys['incr'], 60);
$redis->incr($keys['incr'], 1);
$redis->set($keys['incr1'], 60);  //保存整数可以实现自增
$redis->incr($keys['incr1']);
$redis->set($keys['incrStr'], '10');  //保存数字字符串,无法实现自增
$redis->incr($keys['incrStr']);
$result = $redis->mget($keys);
var_dump($result);